# -*- coding: utf-8 -*-

# run_app.py
import subprocess
import sys
import os

def install_requirements():
    """安装依赖包"""
    subprocess.check_call([
        sys.executable, "-m", "pip", "install", 
        "streamlit", "streamlit-chat", "streamlit-elements", 
        "streamlit-option-menu", "requests", "redis", "pandas", "plotly"
    ])

def run_streamlit_app():
    """运行Streamlit应用"""
    os.chdir("frontend")
    subprocess.run([
        "streamlit", "run", "streamlit_app.py", 
        "--server.port", "8501",
        "--server.address", "0.0.0.0"
    ])

if __name__ == "__main__":
    print("🚀 正在启动智能模型群聊系统...")
    
    try:
        install_requirements()
        print("✅ 依赖安装完成")
        
        print("🌟 启动Streamlit应用...")

        run_streamlit_app()
        
    except Exception as e:
        print(f"❌ 启动失败: {str(e)}")
        sys.exit(1)